package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Button;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

public class UC3Activity extends AppCompatActivity {

    private ImageView imageView;
    private List<Integer> imageList = new ArrayList<>();
    private int currentIndex = 0;
    private Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uc3);

        imageView = findViewById(R.id.imageView);

        // 添加图片资源
        imageList.add(R.drawable.image);
        imageList.add(R.drawable.image2);
        imageList.add(R.drawable.image3);
        imageList.add(R.drawable.image4);
        imageList.add(R.drawable.image5);

        // 初始化返回按钮
        Button btnBack = findViewById(R.id.btnBack);
        btnBack.setOnClickListener(v -> {
            // 返回主界面
            Intent intent = new Intent(UC3Activity.this, MainActivity.class);
            startActivity(intent);
        });

        // 定时切换图片
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                currentIndex = (currentIndex + 1) % imageList.size();
                imageView.setImageResource(imageList.get(currentIndex));
                handler.postDelayed(this, 2000); // 每隔2秒切换一次
            }
        }, 2000);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
    }
}